﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Configuration;
using System.ComponentModel;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Linq.Expressions;
using System.Reflection;

namespace Prodma.DataAccess.Helper.LinqExpressions
{
     public class QueryOlustur
    {
         public static string Urunler(Dictionary<string, string> parameters)
         {
             string sql = "";
             if (parameters.ContainsKey("OrijinalKod"))
             {
                 sql = Query(sql, parameters["OrijinalKod"], "OrijinalKod");
             }
             if (parameters.ContainsKey("StokKod"))
             {
                 sql = Query(sql, parameters["StokKod"], "UrunKodu");
             }
             if (parameters.ContainsKey("StokAd"))
             {
                 sql = Query(sql, parameters["StokAd"], "UrunAdi");
             }
             if (parameters.ContainsKey("StokDurumID"))
             {
                 sql = Miktar(sql, parameters["StokDurumID"], "StokDurumID");
             }
             return sql;
         }

         private static string Query(string sql, string deger, string alanAd)
         {
             if (sql != "")
                 sql += "AND";
             sql += "(" + alanAd + ">=\"" + deger + "\")";
             return sql;
         }
         private static string Miktar(string sql, string deger, string alanAd)
         {
             if (sql != "")
                 sql += "AND";
             sql += "(" + alanAd + "==" + deger + ")";
             return sql;
         }
         private static string queryMiktar(string[] Secilenler, string alanAdi)
         {
             // sql = " AND ";
             decimal temp = 0;
             int donguIdex = 0;

             string sql = " AND ";
             foreach (string idler in Secilenler)
             {
                 temp = Convert.ToDecimal(idler);
                 if (donguIdex == 0)
                 {
                     sql += "(" + alanAdi + ">" + temp;

                 }
                 else
                 {
                     sql += " AND  " + alanAdi + "<" + temp;

                 }
                 donguIdex++;
             }
             sql += ")";
             return sql;
         }
         private static string querylist(String sql, string[] Secilenler, string alanAdi)
         {
             if (Secilenler.Length>0 && Secilenler[0] == "") return "";
             int temp = 0;
             int donguIdex = 0;
             string strSql = "";
             strSql = sql != "" ? " AND " : "";
             foreach (string idler in Secilenler)
             {
                 if (idler != "")
                 {
                     temp = Convert.ToInt32(idler);
                     if (donguIdex == 0)
                     {
                         strSql += "(" + alanAdi + "==" + temp;
                     }
                     else
                     {
                         strSql += " or  " + alanAdi + "==" + temp;
                     }
                 }
                 donguIdex++;
             }
             if (strSql != "") strSql += ")";
             return strSql;
         }
         private static string querylistTers(String sql, string[] Secilenler, string alanAdi)
         {
             if (Secilenler.Length > 0 && Secilenler[0] == "") return "";
             int temp = 0;
             int donguIdex = 0;
             string strSql = "";
             strSql = sql != "" ? " AND " : "";
             foreach (string idler in Secilenler)
             {
                 if (idler != "")
                 {
                     temp = Convert.ToInt32(idler);
                     if (donguIdex == 0)
                     {
                         strSql += "(" + alanAdi + "!=" + temp;
                     }
                     else
                     {
                         strSql += " AND  " + alanAdi + "!=" + temp;
                     }
                 }
                 donguIdex++;
             }
             if (strSql != "") strSql += ")";
             return strSql;
         }
     }
}
